import { SetMetadata } from '@nestjs/common';

export const IS_PUBLIC_KEY = 'isPublic';
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
import { Controller, Get, Post, Request, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
// import { LocalAuthGuard } from 'src/core/auth/local.auth.guard';
import { AuthGuard } from '@nestjs/passport';
import { AuthService } from 'src/core/auth/auth.service';
import { LoginUserDTO } from 'src/dto/user/login-user.dto';
// import { Public } from 'src/common/decorators/public.decorator';

@ApiTags('user')
// 这个很重要，没有他，swagger请求头不会带token发送请求
@ApiBearerAuth()
@Controller('user')
export class UserController {
    constructor(private readonly authService: AuthService) { }

    @ApiOperation({ summary: "用户登录" })
    @Public()// 使用了该注解就不用进行jwt校验的装饰器
    @UseGuards(AuthGuard('local'))
    // @UseGuards(LocalAuthGuard) 
    @Post("login")
    @ApiBody({
        type: LoginUserDTO,
        description: "请求体参数"
    })
    async login(@Request() req) {
        // console.log("gggggggggS",req.user);
        return this.authService.login(req.user);
    }

    @Get("profile")
    getProfile(@Request() req) {
        // console.log("profile");
        // 获取到用户的token中的内容
        return req.user
    }
}